]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-app-system: Do not compare startup-wm classes with full desktop IDs
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 23 Mar 2023 23:02:16 +0000 (00:02 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 20 Apr 2023 15:11:58 +0000 (15:11 +0000)
When fetching the desktop ids into a map of startup-wm classes we meant
to give the ones that match the desktop ID more priority, however
this did not happen because we were always comparing a desktop
file id, including the `.desktop` suffix, with a wm-class that generally
does not include that.

This is the case of gnome-system-monitor, that provides two desktop
files, one of which is OnlyShowIn=KDE but both have the same
StartupWMClass and thus the first parsed is preferred, even though its
desktop-id is gnome-system-monitor-kde.

As per this, remove the .desktop suffix when comparing it with the
startup-wm-class, keeping the old check just in case.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2721>

src/shell-app-system.c

index f9d74ed5caccab4652b3262ce2c0cc01affce280..e042a6747921cf458447fb50b8f2223697c9669e 100644 (file)
@@ -91,6 +91,25 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
                  G_TYPE_NONE, 0);
 }
 
+/*
+ * Check whether @wm_class matches @id exactly when ignoring the .desktop suffix
+ */
+static gboolean
+startup_wm_class_is_exact_match (const char *id,
+                                 const char *wm_class)
+{
+  size_t wm_class_len;
+
+  if (!g_str_has_prefix (id, wm_class))
+    return FALSE;
+
+  wm_class_len = strlen (wm_class);
+  if (id[wm_class_len] == '\0')
+    return TRUE;
+
+  return g_str_equal (id + wm_class_len, ".desktop");
+}
+
 static void
 scan_startup_wm_class_to_id (ShellAppSystem *self)
 {
@@ -116,7 +135,8 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
       /* In case multiple .desktop files set the same StartupWMClass, prefer
        * the one where ID and StartupWMClass match */
       old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class);
-      if (old_id == NULL || strcmp (id, startup_wm_class) == 0)
+      if (old_id == NULL ||
+          startup_wm_class_is_exact_match (id, startup_wm_class))
         g_hash_table_insert (priv->startup_wm_class_to_id,
                              g_strdup (startup_wm_class), g_strdup (id));
     }